package com.sise.controller;

import com.alibaba.dubbo.common.utils.StringUtils;
import com.sise.constants.RpcCommonConstant;
import com.sise.dto.FilterWordDTO;
import com.sise.dto.RpcRespDTO;
import com.sise.service.FilterService;
import com.sise.service.UserService;
import com.sise.vo.WsResponseMsgVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author idea
 * @data 2019/6/4
 */
@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private FilterService filterService;


    @GetMapping(value = "/filter")
    public WsResponseMsgVO<String> filter(String word){
        if(StringUtils.isBlank(word)){
            return WsResponseMsgVO.builderFailedErrParam(null);
        }
        FilterWordDTO filterWordDTO=new FilterWordDTO();
        filterWordDTO.setChannel(-1);
        filterWordDTO.setContent(word);
        filterWordDTO.setMemberId(1001L);
        RpcRespDTO<String> rpcRespDTO = filterService.filter(filterWordDTO);
        if (rpcRespDTO.getCode().equals(RpcCommonConstant.CODE_SUCCESS)) {
            String filterWord = rpcRespDTO.getData();
            System.out.println(filterWord);
            return WsResponseMsgVO.builderSuccessRespData(filterWord);
        }
        return WsResponseMsgVO.builder(false, RpcCommonConstant.MSG_ERR_UNKNOW, null);
    }

    @GetMapping(value = "/get-word")
    public WsResponseMsgVO<String> getWord(String word) {
        RpcRespDTO<String> rpcRespDTO = userService.filter(word);
        if (rpcRespDTO.getCode().equals(RpcCommonConstant.CODE_SUCCESS)) {
            String filterWord = rpcRespDTO.getData();
            System.out.println(filterWord);
            return WsResponseMsgVO.builderSuccessRespData(filterWord);
        }
        return WsResponseMsgVO.builder(false, RpcCommonConstant.MSG_ERR_UNKNOW, null);
    }
}
